package com.cn.wanxi.service;

import com.cn.wanxi.dao.NewsDao;
import com.cn.wanxi.model.NewsModel;

import java.util.ArrayList;
import java.util.List;

public class NewsService {
    /**
     * 首页新闻数据
     *
     * @return
     */
    public List<NewsModel> getNewsModelListForHomePage() {
        List<NewsModel> list = new ArrayList<>();
        NewsDao newsDao = new NewsDao();
        int length = newsDao.titlesForHomePage.length;
        for (int i = 0; i < length; i++) {
            NewsModel model = new NewsModel();
            model.setTitle(newsDao.titlesForHomePage[i]);
            model.setContent(newsDao.contentsForHomePage[i]);
            list.add(model);
        }
        return list;
    }

    /**
     * 针对新闻页面封装数据
     *
     * @return
     */
    public List<NewsModel> getNewsModelListForNewsPage() {
        List<NewsModel> list = new ArrayList<>();
        NewsDao newsDao = new NewsDao();
        int length = newsDao.titlesForHomePage.length;
        for (int i = 0; i < length; i++) {
            NewsModel model = new NewsModel();
            model.setTitle(newsDao.titlesForNewsPage[i]);
            model.setContent(newsDao.contentsForNewsPage[i]);
            model.setCreateDate(newsDao.createTimeForNewsPage[i]);
            model.setImg(newsDao.imgForNewsPage[i]);
            list.add(model);
        }
        return list;
    }
}
